package filter;

import javax.servlet.*;
import java.io.IOException;

//@WebFilter(filterName = "EnCodingFilter",value = "/*") //对本网站的所有请求过滤一次编码问题
public class EnCodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        //实际开发中所有的servlet都需要设置请求与响应的编码 造成了代码的冗余
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        chain.doFilter(req, resp);
    }

    @Override
    public void destroy() {

    }
}
